<?php
/**
 * Created by PhpStorm.
 * User: 程阳
 * Date: 2017/2/21
 * Time: 11:13
 */

namespace Admin\Controller;


use Common\Controller\AdminController;

class TypeController extends AdminController
{
    public function lists(){
        $listsData = D('Type')->select();
        $this->assign('listsData',$listsData);
        $this->display();
    }

    public function addType(){
        $tid = I('get.tid');
        if(IS_POST){
            $data = I('post.');
            if($tid){
                $data['tid'] = $tid;
            }
            $this->store(D("Type"),$data,function(){
                $this->success('类型提交成功',u('admin/type/lists'));die;
            });
        }
        if($tid){
            $oldData = D('Type')->where('tid='.$tid)->find();
            $this->assign('oldData',$oldData);
        }
        $this->display();
    }

    public function delType(){
        $tid = I('post.id');
        $res = D('Type')->delete($tid);
        if($res){
            return show(1,'删除成功');
        }else{
            return show(0,'删除失败');
        }
    }
}